<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    <div class="layui-form-item">
        <label class="layui-form-label required">真实姓名</label>
        <div class="layui-input-block">
            <input type="text" name="realName" lay-verify="required" lay-reqtext="真实姓名不能为空" placeholder="请填写真实姓名" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">用户id</label>
        <div class="layui-input-block">
            <input type="text" name="userId" lay-verify="required" lay-reqtext="用户id不能为空" placeholder="请填写用户id" value="" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">性别</label>
        <div class="layui-input-block">
            <select name="sex" lay-filter="distributorSex">
                <option value="男">男</option>
                <option value="女">女</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">年龄层</label>
        <div class="layui-input-block">
            <select name="age" lay-filter="distributorAge">
                <option value="10后">10后</option>
                <option value="00后">00后</option>
                <option value="90后">90后</option>
                <option value="80后">80后</option>
                <option value="70后">70后</option>
                <option value="60后">60后</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item" id="area-picker">
        <div class="layui-form-label">所在地区</div>
        <div class="layui-input-inline" style="width: 200px;">
            <select name="province" class="province-selector" data-value="" lay-filter="province-1">
                <option value="" >请选择省</option>
            </select>
        </div>
        <div class="layui-input-inline" style="width: 200px;">
            <select name="city" class="city-selector" data-value="" lay-filter="city-1">
                <option value="" >请选择市</option>
            </select>
        </div>
        <input type="text" name="area" value="" hidden>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">所在街道</label>
        <div class="layui-input-block">
            <input type="text" name="street" lay-verify="required" lay-reqtext="所在街道不能为空" placeholder="请填写公告标题" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">服务名称</label>
        <div class="layui-input-block">
            <input type="text" name="storeName" lay-verify="required" lay-reqtext="店铺名称不能为空" placeholder="请填写公告标题" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">服务类型</label>
        <div class="layui-input-block">
            <select name="storyType">
                <option value="">不选</option>
                <option value="线上服务商">线上服务商</option>
                <option value="线上店铺">线上店铺</option>
                <option value="主播达人">主播达人</option>
                <option value="线下零售">线下零售</option>
                <option value="线下零售">线下零售</option>
                <option value="线下网点">线下网点</option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">店铺标签</label>
        <div class="layui-input-block">
            <div id="keywordId"></div>
            <input type="text" name="storeTags" value="" hidden>
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">头像</label>
        <div class="layui-input-block">
            <input type="text" name="storeAvatar" lay-verify="required" lay-reqtext="店铺头像不能为空" placeholder="请填写公告标题" value="" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>
<script src="../../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="../../js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script src="../../lib/common/common.js" charset="utf-8"></script>
<script src="../../lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
<script src="../../js/lay-module/xm-select-master/dist/xm-select.js" charset="utf-8"></script>
<script>

    layui.use(['layer', 'form', 'layarea'], function () {
        var form = layui.form,
            layer = layui.layer,
            layarea = layui.layarea,
            $ = layui.$;

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            var index = layer.alert("确定提交吗？", {
                title: '提示'
            }, function () {
                let myMsg = layer.msg("正在提交...",{
                    icon:16,
                    time:-1
                })
                $.ajax({
                    type:"post",
                    url:'/provider/save',
                    data:JSON.stringify(data.field),
                    dataType:'json',
                    contentType: 'application/json; charset=UTF-8',
                    success:function(req){
                        layer.msg("已添加");
                        layer.close(index);
                        // 关闭弹出层
                        setTimeout(function () {
                            layer.close(myMsg);//手动关闭
                            let iframeIndex = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(iframeIndex);
                        }, 1500);
                    },
                    error:function(e){
                        layer.msg("添加失败");
                        layer.close(myMsg);//手动关闭
                    }
                })

            });

            return false;
        });

    });
    let xm_select = xmSelect.render({
        el: '#keywordId',
        language: 'zn',
        direction: 'down',
        data: [],
        on: function(data){
            let keyword = ''
            if(isNotNull(data.arr) && data.arr.length>0){
                for (const i in data.arr) {
                    if(keyword == ''){
                        keyword = data.arr[i].value
                    }else{
                        keyword += "," + data.arr[i].value
                    }
                }
            }
            $('input[name="storeTags"]').val(keyword);
        },
        filterable: true,
        create: function(val, arr){
            //返回一个创建成功的对象, val是搜索的数据, arr是搜索后的当前页面数据
            return {
                name: val,
                value: val
            }
        }
    })
</script>
</body>
</html>
